package com.example.wechat

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class ChatAdapter(val chatInfos: ArrayList<ChatInfo>) : RecyclerView.Adapter<ChatAdapter.chatInfoViewHolder>() {

    inner class chatInfoViewHolder(itemView: View) :RecyclerView.ViewHolder(itemView){
        val headimg=itemView.findViewById<ImageView>(R.id.chat_img_frihead)
        val msg=itemView.findViewById<TextView>(R.id.chat_text_fri_lastmsg)
        val name=itemView.findViewById<TextView>(R.id.chat_text_fri_name)
        val time=itemView.findViewById<TextView>(R.id.chat_text_fri_lastime)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): chatInfoViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_chat,parent,false)
        val holder = chatInfoViewHolder(view)
        return holder
    }

    override fun onBindViewHolder(holder: chatInfoViewHolder, position: Int) {
        val obj = chatInfos[position]
        holder.headimg.setImageResource(obj.chatinfo_headimg)
        holder.msg.text = obj.chatinfo_msg
        holder.name.text = obj.chatinfo_name
        holder.time.text = obj.chatinfo_time

    }

    override fun getItemCount(): Int {
        return chatInfos.size
    }

}
